// components/user/banner/banner.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    user: {
      username: '',
      id: -1,
      avatarUrl: ''
    },
    isLogin: false
  },

  lifetimes: {
    async attached () {
      const getUserInfo = (globalData) => {
        return new Promise((resolve, reject) => {
          const clock = setInterval(() => {
            if (globalData.userInfo && typeof globalData.userInfo.fresh !== 'undefined') {
              resolve(globalData.userInfo)
              clearInterval(clock)
            }
          }, 100)
        }).then (res => {
          this.setData({
            ['user.username']: res.username,
            ['user.avatarUrl']: res.avatarUrl,
            ['user.id']: res._id,
            isLogin: true
          })
        })
      }
      await getUserInfo(app.globalData)
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {

  }
})
